﻿// JScript File

function IsNull(o)
{
	return ("undefined" == typeof(o) || "unknown" == typeof(o) || null == o)
}

function formatString()
{
    if( arguments.length == 0 )
    {
        return null;
    }
    var str = arguments[0];
    for(var i=1;i<arguments.length;i++)
    {
        var re = new RegExp('\\{' + (i-1) + '\\}','gm');
        str = str.replace(re, arguments[i]);
    }
    return str;
}

function OpenWindow(url, name)
{
    if(IsNull(name))
    {
        name = "_blank";
    }
	return window.open(url, name, "toolbar=no,menubar=no,status=yes,resizable=yes");
}

function HtmlEncode (str)
{
   var div = document.createElement('div');
   var text = document.createTextNode(str);
   div.appendChild(text);
   var s = div.innerHTML;
   s = s.replace("&#160;", "&nbsp;");
   s = s.replace("&#60;", "&lt;");
   s = s.replace("&#62;", "&gt;");
   s = s.replace("&#38;", "&amp;");
   s = s.replace("&#34;", "&quot;");
   return s;
}

function HtmlDecode (str)
{
   var div = document.createElement('div');
   div.innerHTML = str;
   var text = "";
   if(!IsNull(div.childNodes[0]))
   {
	 text = div.childNodes[0].nodeValue;
   }
   return text;
}

function hasScriptManager()
{
    if(typeof(Sys) != 'undefined')
    {
        if(typeof(Sys.WebForms) != 'undefined')
        {
            if(typeof(Sys.WebForms.PageRequestManager) != 'undefined')
                return true;
        }
    }
    return false;
}

function attachEndRequestHandler(func)
{
    if(hasScriptManager())
    {
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(func);
    }
}
